<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 12528
  Date: 2022/4/6
  Time: 19:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>业务开通与关闭</title>
    <link rel="stylesheet" type="text/css"
          href='<c:url context="${pageContext.request.contextPath}" value="/easyui/themes/default/easyui.css"/>'>
    <link rel="stylesheet" type="text/css"
          href='<c:url context="${pageContext.request.contextPath}" value="/easyui/themes/icon.css"/>'>
    <link rel="stylesheet" type="text/css"
          href='<c:url context="${pageContext.request.contextPath}" value="/easyui/css/demo.css"/>'>
    <script type="text/javascript"
            src='<c:url context="${pageContext.request.contextPath}" value="/easyui/jquery.min.js"/>'></script>
    <script type="text/javascript"
            src='<c:url context="${pageContext.request.contextPath}" value="/easyui/jquery.easyui.min.js"/>'></script>
    <script type="text/javascript"
            src='<c:url context="${pageContext.request.contextPath}" value="/easyui/js/validateExtends.js"/>'></script>
    <script type="text/javascript" src='<c:url context="${pageContext.request.contextPath}" value="/easyui/js/easyui-lang-zh_CN.js"/>'></script>

    <script type="text/javascript">

        //开通
        function open1() {
            var selectRow = $("#dataList").datagrid("getSelected");
            var aid = selectRow.aid + ",";
            $.messager.confirm("消息提醒", "将开通【" + selectRow.bname + "】业务，确认继续？", function (r) {
                if (r) {
                    $.ajax({
                        type: "post",
                        url: "/MSOS/bmanager?action=open&aid=" + aid,
                        success: function (msg) {
                            if (msg.status == 200) {
                                //刷新表格
                                $("#dataList").datagrid("reload");
                                $("#dataList").datagrid("uncheckAll");
                                return;
                            } else {
                                $.messager.alert("消息提醒", msg.msg, "warning");
                                return;
                            }
                        }
                    });
                }
                $("#dataList").datagrid("reload");
                $("#dataList").datagrid("uncheckAll");
            });
        }

        //关闭
        function close1() {
            var selectRow = $("#dataList").datagrid("getSelected");
            var aid = selectRow.aid + ",";
            $.messager.confirm("消息提醒", "将关闭【" + selectRow.bname + "】业务，确认继续？", function (r) {
                if (r) {
                    $.ajax({
                        type: "post",
                        url: "/MSOS/bmanager?action=close&aid=" + aid,
                        success: function (msg) {
                            if (msg.status == 200) {
                                //刷新表格
                                $("#dataList").datagrid("reload");
                                $("#dataList").datagrid("uncheckAll");
                                return;
                            } else {
                                $.messager.alert("消息提醒", msg.msg, "warning");
                                return;
                            }
                        }
                    });
                }
                $("#dataList").datagrid("reload");
                $("#dataList").datagrid("uncheckAll");
            });
        }

        //修改
        function edit() {
            table = $("#editTable");
            var selectRows = $("#dataList").datagrid("getSelections");
            if (selectRows.length != 1) {
                $.messager.alert("消息提醒", "请选择一条数据进行操作!", "warning");
            } else {
                $("#editDialog").dialog("open");
            }
        }

        $(function () {
            //datagrid初始化
            $('#dataList').datagrid({
                title: '业务开通与关闭',
                iconCls: 'icon-more',//图标
                border: true,
                collapsible: false,//是否可折叠的
                fit: true,//自动大小
                method: "get",
                url: "/MSOS/bmanager?action=data",
                idField: 'aid',
                singleSelect: false,//是否单选
                pagination: true,//分页控件
                rownumbers: true,//行号
                sortName: 'aid',
                sortOrder: 'ASC',
                remoteSort: false,
                columns: [[
                    {field: 'chk', checkbox: true, width: 50},
                    {field: 'aid', title: '业务编号', width: 80, sortable: true},
                    {field: 'bname', title: '业务名称', width: 200},
                    {field: 'bintro', title: '业务简介', width: 200},
                    {field: 'bimg', title: '业务图片', width: 200},
                    {field: 'bmoney', title: '业务资费', width: 200},
                    {field: 'open', title: '开通', width: 80, align: 'center'},
                    {field: 'close', title: '关闭', width: 80, align: 'center'},
                    {
                        field: 'edit', title: '修改', width: 80, align: 'center',
                        formatter: function () {
                            return $("#edit").html();
                        }
                    },
                ]],
                toolbar: "#toolbar"
            });

            //设置分页控件
            var p = $('#dataList').datagrid('getPager');
            $(p).pagination({
                pageSize: 10,//每页显示的记录条数，默认为10
                pageList: [1, 2, 4, 8, 10],//可以设置每页记录条数的列表
                beforePageText: '第',//页数文本框前显示的汉字
                afterPageText: '页    共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
            });
            //设置工具类按钮
            $("#add").click(function () {
                table = $("#addTable");
                $("#addDialog").dialog("open");
            });
            //删除
            $("#delete").click(function () {
                var selectRows = $("#dataList").datagrid("getSelections");
                var selectLength = selectRows.length;
                if (selectLength == 0) {
                    $.messager.alert("消息提醒", "请选择业务进行删除!", "warning");
                } else {
                    var aids = "";
                    $(selectRows).each(function (i, row) {
                        aids += row.aid + ",";
                    });
                    $.messager.confirm("消息提醒", "将删除与当前选中业务相关的所有数据，确认继续？", function (r) {
                        if (r) {
                            $.ajax({
                                type: "delete",
                                url: "/MSOS/bmanager?aids=" + aids,
                                success: function (msg) {
                                    if (msg.status == 200) {
                                        $.messager.alert("消息提醒", "删除成功!", "info");
                                        //刷新表格
                                        $("#dataList").datagrid("reload");
                                        $("#dataList").datagrid("uncheckAll");
                                    } else {
                                        $.messager.alert("消息提醒", msg.msg, "warning");
                                        return;
                                    }
                                }
                            });
                        }
                    });
                }
            });

            //任选开通
            $("#open_all").click(function () {
                var selectRows = $("#dataList").datagrid("getSelections");
                var selectLength = selectRows.length;
                if (selectLength == 0) {
                    $.messager.alert("消息提醒", "请选择业务进行开通!", "warning");
                } else {
                    var aids = "";
                    $(selectRows).each(function (i, row) {
                        aids += row.aid + ",";
                    });
                    $.messager.confirm("消息提醒", "将开通所选中的业务，确认继续？", function (r) {
                        if (r) {
                            $.ajax({
                                type: "post",
                                url: "/MSOS/bmanager?action=open&aid=" + aids,
                                success: function (msg) {
                                    if (msg.status == 200) {
                                        //刷新表格
                                        $("#dataList").datagrid("reload");
                                        $("#dataList").datagrid("uncheckAll");
                                        return;
                                    } else {
                                        $.messager.alert("消息提醒", msg.msg, "warning");
                                        return;
                                    }
                                }
                            });
                        }
                        $("#dataList").datagrid("reload");
                        $("#dataList").datagrid("uncheckAll");
                    });
                }
            });

            //任选关闭
            $("#close_all").click(function () {
                var selectRows = $("#dataList").datagrid("getSelections");
                var selectLength = selectRows.length;
                if (selectLength == 0) {
                    $.messager.alert("消息提醒", "请选择业务进行关闭!", "warning");
                } else {
                    var aids = "";
                    $(selectRows).each(function (i, row) {
                        aids += row.aid + ",";
                    });
                    $.messager.confirm("消息提醒", "将关闭所选中的业务，确认继续？", function (r) {
                        if (r) {
                            $.ajax({
                                type: "post",
                                url: "/MSOS/bmanager?action=close&aid=" + aids,
                                success: function (msg) {
                                    if (msg.status == 200) {
                                        //刷新表格
                                        $("#dataList").datagrid("reload");
                                        $("#dataList").datagrid("uncheckAll");
                                        return;
                                    } else {
                                        $.messager.alert("消息提醒", msg.msg, "warning");
                                        return;
                                    }
                                }
                            });
                        }
                        $("#dataList").datagrid("reload");
                        $("#dataList").datagrid("uncheckAll");
                    });
                }
            });

            //设置添加窗口
            $("#addDialog").dialog({
                title: "添加业务",
                width: 850,
                height: 550,
                iconCls: "icon-add",
                modal: true,
                collapsible: false,
                minimizable: false,
                maximizable: false,
                draggable: true,
                closed: true,
                buttons: [
                    {
                        text: '添加',
                        plain: true,
                        iconCls: 'icon-user_add',
                        handler: function () {
                            var validate = $("#addForm").form("validate");
                            if (!validate) {
                                $.messager.alert("消息提醒", "请检查你输入的数据!", "warning");
                                return;
                            } else {
                                var bname = $("#add_bname").textbox("getText");
                                var bmoney = $("#add_bmoney").textbox("getText");
                                var bintro = $("#add_bintro").textbox("getText");
                                var bimg = $("#add_bimg").textbox("getText");
                                var data = {
                                    bname: bname,
                                    bmoney: bmoney,
                                    bintro: bintro,
                                    bimg: bimg,
                                };

                                $.ajax({
                                    type: "post",
                                    url: "/MSOS/bmanager?action=add",
                                    data: data,
                                    success: function (msg) {
                                        if (msg.status == 200) {
                                            $.messager.confirm("消息提醒", "删除成功! 是否继续添加业务?", function (r) {
                                                if (r) {
                                                    $("#addDialog").dialog("open");
                                                }
                                            });
                                            //关闭窗口
                                            $("#addDialog").dialog("close");
                                            //清空原表格数据
                                            $("#add_bname").textbox('setValue', "");
                                            $("#add_bmoney").textbox('setValue', "");
                                            $("#add_bintro").textbox('setValue', "");
                                            $("#add_bimg").textbox('setValue', "");

                                            //重新刷新页面数据
                                            $('#dataList').datagrid("reload");

                                        } else {
                                            $.messager.alert("消息提醒", msg.msg, "warning");
                                            return;
                                        }
                                    }
                                });
                            }
                        }
                    },
                    {
                        text: '重置',
                        plain: true,
                        iconCls: 'icon-reload',
                        handler: function () {
                            $("#add_bname").textbox('setValue', "");
                            $("#add_bmoney").textbox('setValue', "");
                            $("#add_bintro").textbox('setValue', "");
                            $("#add_bimg").textbox('setValue', "");
                        }
                    },
                ],
                onClose: function () {
                    $("#add_bname").textbox('setValue', "");
                    $("#add_bmoney").textbox('setValue', "");
                    $("#add_bintro").textbox('setValue', "");
                    $("#add_bimg").textbox('setValue', "");
                }
            });

            //编辑业务信息
            $("#editDialog").dialog({
                title: "修改业务信息",
                width: 850,
                height: 550,
                iconCls: "icon-edit",
                modal: true,
                collapsible: false,
                minimizable: false,
                maximizable: false,
                draggable: true,
                closed: true,
                buttons: [
                    {
                        text: '提交',
                        plain: true,
                        iconCls: 'icon-user_add',
                        handler: function () {
                            var validate = $("#editForm").form("validate");
                            if (!validate) {
                                $.messager.alert("消息提醒", "请检查你输入的数据!", "warning");
                                return;
                            } else {
                                var aid = $("#edit_aid").textbox("getText");
                                var bname = $("#edit_bname").textbox("getText");
                                var bmoney = $("#edit_bmoney").textbox("getText");
                                var bintro = $("#edit_bintro").textbox("getText");
                                var bimg = $("#edit_bimg").textbox("getText");
                                var data = {
                                    aid:aid,
                                    bname: bname,
                                    bmoney: bmoney,
                                    bintro: bintro,
                                    bimg: bimg,
                                };

                                $.ajax({
                                    type: "put",
                                    url: "/MSOS/bmanager",
                                    data: JSON.stringify(data),
                                    contentType: 'application/json',
                                    success: function (msg) {
                                        if (msg.status == 200) {
                                            $.messager.alert("消息提醒", "修改成功!", "info");
                                            //关闭窗口
                                            $("#editDialog").dialog("close");
                                            //清空原表格数据
                                            $("#edit_bname").textbox('setValue', "");
                                            $("#edit_bmoney").textbox('setValue', "");
                                            $("#edit_bintro").textbox('setValue', "");
                                            $("#edit_bimg").textbox('setValue', "");

                                            //重新刷新页面数据
                                            $('#dataList').datagrid("reload");
                                            $('#dataList').datagrid("uncheckAll");

                                        } else {
                                            $.messager.alert("消息提醒", msg.msg, "warning");
                                            return;
                                        }
                                    }
                                });
                            }
                        }
                    },
                    {
                        text: '重置',
                        plain: true,
                        iconCls: 'icon-reload',
                        handler: function () {
                            $("#edit_name").textbox('setValue', "");
                            $("#edit_phone").textbox('setValue', "");
                            $("#edit_qq").textbox('setValue', "");

                            $(table).find(".chooseTr").remove();

                        }
                    },
                ],
                onBeforeOpen: function () {
                    var selectRow = $("#dataList").datagrid("getSelected");
                    //设置值
                    $("#edit_aid").textbox('setValue', selectRow.aid);
                    $("#edit_bname").textbox('setValue', selectRow.bname);
                    $("#edit_bmoney").textbox('setValue', selectRow.bmoney);
                    $("#edit_bintro").textbox('setValue', selectRow.bintro);
                    $("#edit_bimg").textbox('setValue', selectRow.bimg);
                    //$("#edit_photo").attr("src", "PhotoServlet?method=GetPhoto&type=3&number="+selectRow.number);
                },
                onClose: function () {
                    $("#edit_bname").textbox('setValue', "");
                    $("#edit_bmoney").textbox('setValue', "");
                    $("#edit_bintro").textbox('setValue', "");
                    $("#edit_bimg").textbox('setValue', "");
                }
            });
        });
    </script>
</head>
<body>
<!-- 数据列表 -->
<table id="dataList" cellspacing="0" cellpadding="0">

</table>

</div>
<div id="edit">
    <button id='edit_btn' onclick="edit()">修改</button>
</div>

<!-- 工具栏 -->
<div id="toolbar">
    <div style="float: left;"><a id="add" href="javascript:;" class="easyui-linkbutton"
                                 data-options="iconCls:'icon-add',plain:true">添加</a></div>

    <div style="float: left;" class="datagrid-btn-separator"></div>

    <div><a id="delete" href="javascript:;" class="easyui-linkbutton"
            data-options="iconCls:'icon-some-delete',plain:true">删除</a></div>

    <div style="float: left;" class="datagrid-btn-separator"></div>

    <div style="float: left;"><a id="open_all" href="javascript:;" class="easyui-linkbutton"
                                 data-options="iconCls:'icon-edit',plain:true">任选开通</a></div>

    <div style="float: left;" class="datagrid-btn-separator"></div>

    <div><a id="close_all" href="javascript:;" class="easyui-linkbutton"
            data-options="iconCls:'icon-some-delete',plain:true">任选关闭</a></div>
</div>

<!-- 添加窗口 -->
<div id="addDialog" style="padding: 10px;">
    <div style=" position: absolute; margin-left: 560px; width: 250px; height: 300px; border: 1px solid #EEF4FF"
         id="photo">
        <img alt="照片" style="max-width: 250px; max-height: 300px;" title="照片" src="/image/02.png"/>
    </div>
    <form id="addForm" method="post">
        <table id="addTable" border=0 style="width:800px; table-layout:fixed;" cellpadding="6">
            <tr>
                <td style="width:40px">业务名称:</td>
                <td colspan="3">
                    <input id="add_bname" class="easyui-textbox" style="width: 200px; height: 30px;" type="text"
                           name="bname" data-options="required:true, validType:'repeat', missingMessage:'请输入业务名称'"/>
                </td>
                <td style="width:80px"></td>
            </tr>
            <tr>
                <td>业务资费:</td>
                <td colspan="4"><input id="add_bmoney" style="width: 200px; height: 30px;" class="easyui-textbox"
                                       type="text" name="bmoney"
                                       data-options="required:true, missingMessage:'请输入业务资费'"/>
                </td>
            </tr>
            <tr>
                <td>业务简介:</td>
                <td colspan="4"><input id="add_bintro" style="width: 200px; height: 30px;" class="easyui-textbox"
                                       type="text" name="bintro" data-options="required:true, missingMessage:'请输入业务简介'">
                </td>
            </tr>
            <tr>
                <td>业务图片:</td>
                <td colspan="4"><input id="add_bimg" style="width: 200px; height: 30px;" class="easyui-textbox"
                                       type="text" name="bimg" data-options="required:true, missingMessage:'请上传业务图片'"/>
                </td>
            </tr>
        </table>
    </form>
</div>

<!-- 修改窗口 -->
<div id="editDialog" style="padding: 10px">
    <div style=" position: absolute; margin-left: 560px; width: 250px; height: 300px; border: 1px solid #EEF4FF">
        <img id="edit_photo" alt="照片" style="max-width: 200px; max-height: 400px;" title="照片" src=""/>
    </div>
    <form id="editForm" method="post">
        <table id="editTable" border=0 style="width:800px; table-layout:fixed;" cellpadding="6">
            <tr>
                <td style="width:40px">业务编号:</td>
                <td colspan="3"><input id="edit_aid" data-options="readonly: true" class="easyui-textbox"
                                       style="width: 200px; height: 30px;" type="text" name="aid"
                                       data-options="required:true, validType:'repeat'"/></td>
                <td style="width:80px"></td>
            </tr>
            <tr>
                <td>业务名称:</td>
                <td><input id="edit_bname" style="width: 200px; height: 30px;" class="easyui-textbox" type="text"
                           name="bname" data-options="required:true, missingMessage:'请输入业务名称'"/></td>
            </tr>
            <tr>
                <td>业务资费:</td>
                <td><input id="edit_bmoney" style="width: 200px; height: 30px;" class="easyui-textbox" type="text"
                           name="bmoney" data-options="required:true, missingMessage:'请输入业务资费'"/></td>
            </tr>
            <tr>
                <td>业务简介:</td>
                <td><input id="edit_bintro" style="width: 200px; height: 30px;" class="easyui-textbox" type="text"
                           name="bintro" data-options="required:true, missingMessage:'请输入业务简介'"/></td>
            </tr>
            <tr>
                <td>业务图片:</td>
                <td><input id="edit_bimg" style="width: 200px; height: 30px;" class="easyui-textbox" type="text"
                           name="bimg" data-options="required:true, missingMessage:'请输入业务图片'"/></td>
            </tr>
        </table>
    </form>
</div>


</body>
</html>
